package cn.livingCloud.controller.core;

import cn.livingCloud.dto.SelfBindingListDto;
import cn.livingCloud.service.SelfBindingService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * 自助绑定后台
 * Created by DingJie on 2016/6/23.
 */
@Controller
@RequestMapping("/admin/self_binding")
public class SelfBindingController {
    @Autowired
    private SelfBindingService service;

    @RequestMapping("/list.htm")
    public String list(SelfBindingListDto listDto, Model model) {
        service.loadSelfBindingListDto(listDto);
        model.addAttribute("listDto", listDto);
        return "self_binding/list";
    }

    @RequestMapping(value = "/self_binding.htm", method = RequestMethod.POST)
    public String selfBinding(String uuid, Model model) {
        if (StringUtils.isEmpty(uuid)) {
            model.addAttribute("fail", "fail");
            return "redirect:list.htm";
        }
        boolean result = service.Binding(uuid);
        if (result) {
            model.addAttribute("success", "success");
        } else {
            model.addAttribute("fail", "fail");
        }
        return "redirect:list.htm";
    }
}
